import {
  toTypedRxJsonSchema,
  type ExtractDocumentTypeFromTypedRxJsonSchema,
  type RxJsonSchema,
} from "rxdb";

const requestBody = {
  raw: {
    type: "string",
  },
  urlencoded: {
    type: "array",
    items: {
      type: "object",
      properties: {
        key: {
          type: "string",
        },
        value: {
          type: "string",
        },
        checked: {
          type: "boolean",
        },
      },
    },
  },
  formdata: {
    type: "object",
    properties: {
      text: {
        type: "array",
        properties: {
          key: {
            type: "string",
          },
          value: {
            type: "string",
          },
          checked: {
            type: "boolean",
          },
        },
      },
      file: {
        type: "array",
        properties: {
          key: {
            type: "string",
          },
          value: {
            type: "string",
          },
          checked: {
            type: "boolean",
          },
          base: {
            type: "string",
          },
        },
      },
    },
  },
};

const stateItems = {
  requestBodyLanguage: {
    type: "string",
  },
  requestBodyNavigation: {
    type: "string",
  },
  requestAuthNavigation: {
    type: "string",
  },
  requestNavigation: {
    type: "string",
  },
  responseNavigation: {
    type: "string",
  },
  responseBodyLanguage: {
    type: "string",
  },
  responseBodyFormatter: {
    type: "string",
  },
  requestExtensionNavigation: {
    type: "string",
  },
  requestLeftSplitterWidthPercentage: {
    type: "number",
  },
  requestRightSplitterWidthPercentage: {
    type: "number",
  },
  isExposeEditDescription: {
    type: "boolean",
  },
  isSendRequestInProgress: {
    type: "boolean",
    default: false,
  },
  isSaveDescriptionInProgress: {
    type: "boolean",
    default: false,
  },
  isSaveRequestInProgress: {
    type: "boolean",
  },
  isParameterBulkEditActive: {
    type: "boolean",
  },
  isHeaderBulkEditActive: {
    type: "boolean",
  },
  isChatbotActive: {
    type: "boolean",
  },
  isChatbotSuggestionsActive: {
    type: "boolean",
  },
  isChatbotGeneratingResponse: {
    type: "boolean",
  },
  isDocAlreadyGenerated: {
    type: "boolean",
  },
  isDocGenerating: {
    type: "boolean",
  },
};

const params = {
  key: {
    type: "string",
  },
  value: {
    type: "string",
  },
  checked: {
    type: "boolean",
  },
};

const httpRequestAuth = {
  bearerToken: {
    type: "string",
  },
  basicAuth: {
    type: "object",
    properties: {
      username: {
        type: "string",
      },
      password: {
        type: "string",
      },
    },
  },
  apiKey: {
    type: "object",
    properties: {
      authKey: {
        type: "string",
      },
      authValue: {
        type: "string",
      },
      addTo: {
        type: "string",
      },
    },
  },
};

const requestItems = {
  name: {
    type: "string",
  },
  method: {
    type: "string",
  },
  operationId: {
    type: "string",
  },
  url: {
    type: "string",
  },
  body: {
    type: "array",
    properties: requestBody,
  },
  selectedRequestBodyType: {
    type: "string",
  },
  selectedRequestAuthType: {
    type: "string",
  },
  queryParams: {
    type: "array",
    properties: params,
  },
  auth: {
    type: "object",
    properties: httpRequestAuth,
  },
  headers: {
    type: "array",
    properties: params,
  },
  state: {
    type: "object",
    properties: stateItems,
  },
  autoGeneratedHeaders: {
    type: "array",
    items: {
      type: "object",
      properties: {
        key: {
          type: "string",
        },
        value: {
          type: "string",
        },
        checked: {
          type: "boolean",
        },
      },
    },
  },
  tests: {
    type: "object",
    properties: {
      testCaseMode: {
        type: "string",
      },
      noCode: {
        type: "array",
        items: {
          type: "object",
          properties: {
            id: {
              type: "string",
            },
            name: {
              type: "string",
            },
            condition: {
              type: "string",
            },
            expectedResult: {
              type: "string",
            },
            testPath: {
              type: "string",
            },
            testTarget: {
              type: "string",
            },
          },
        },
      },
      script: {
        type: "string",
      },
    },
  },
};

export const authProfileItemProperties = {
  authId: { type: "number" },
  name: { type: "string" },
  description: { type: "string" },
  authType: {
    type: "string",
    enum: ["Basic Auth", "Bearer Token", "API Key"],
  },
  auth: {
    type: "object",
    properties: {
      basicAuth: {
        type: "object",
        properties: {
          username: { type: "string" },
          password: { type: "string" },
        },
      },
      bearerToken: { type: "string" },
      apiKey: {
        type: "object",
        properties: {
          authKey: { type: "string" },
          authValue: { type: "string" },
          addTo: {
            type: "string",
            enum: ["Header", "Query Parameter"],
          },
        },
      },
    },
  },
  defaultKey: { type: "boolean" },
  createdAt: { type: "string", format: "date-time" },
  updatedAt: { type: "string", format: "date-time" },
  createdBy: { type: "string" },
  updatedBy: { type: "string" },
};

export const authProfiles = {
  type: "array",
  default: [],
  items: {
    type: "object",
    properties: authProfileItemProperties,
  },
};

export const tabSchemaLiteral = {
  title: "Opened tabs that will be shown on dashboard",
  primaryKey: "tabId",
  type: "object",
  version: 40,
  properties: {
    tabId: {
      // ---- RxDocumentId
      type: "string",
      maxLength: 100,
    },
    id: {
      // ---- MongoDocumentId
      type: "string",
      maxLength: 100,
    },
    name: {
      type: "string",
    },
    description: {
      type: "string",
    },
    isDeleted: {
      type: "boolean",
    },
    activeSync: {
      type: "boolean",
    },
    source: {
      type: "string",
    },
    type: {
      type: "string",
    },
    persistence: {
      type: "string",
    },
    label: {
      type: "string",
    },
    property: {
      type: "object",
      properties: {
        request: {
          type: "object",
          properties: {
            method: {
              type: "string",
            },
            body: {
              type: "object",
              properties: {
                raw: {
                  type: "string",
                },
                urlencoded: {
                  type: "array",
                  items: {
                    type: "object",
                    properties: {
                      key: {
                        type: "string",
                      },
                      value: {
                        type: "string",
                      },
                      checked: {
                        type: "boolean",
                      },
                    },
                  },
                },
                formdata: {
                  type: "array",
                  items: {
                    type: "object",
                    properties: {
                      key: {
                        type: "string",
                      },
                      value: {
                        type: "string",
                      },
                      checked: {
                        type: "boolean",
                      },
                      base: {
                        type: "string",
                      },
                      type: {
                        type: "string",
                      },
                    },
                  },
                },
              },
            },
            url: {
              type: "string",
            },
            headers: {
              type: "array",
              items: {
                type: "object",
                properties: {
                  key: {
                    type: "string",
                  },
                  value: {
                    type: "string",
                  },
                  checked: {
                    type: "boolean",
                  },
                },
              },
            },
            queryParams: {
              type: "array",
              items: {
                type: "object",
                properties: {
                  key: {
                    type: "string",
                  },
                  value: {
                    type: "string",
                  },
                  checked: {
                    type: "boolean",
                  },
                },
              },
            },
            tests: {
              type: "object",
              properties: {
                testCaseMode: {
                  type: "string",
                },
                noCode: {
                  type: "array",
                  items: {
                    type: "object",
                    properties: {
                      id: {
                        type: "string",
                      },
                      name: {
                        type: "string",
                      },
                      condition: {
                        type: "string",
                      },
                      expectedResult: {
                        type: "string",
                      },
                      testPath: {
                        type: "string",
                      },
                      testTarget: {
                        type: "string",
                      },
                    },
                  },
                },
                script: {
                  type: "string",
                },
              },
            },
            autoGeneratedHeaders: {
              type: "array",
              items: {
                type: "object",
                properties: {
                  key: {
                    type: "string",
                  },
                  value: {
                    type: "string",
                  },
                  checked: {
                    type: "boolean",
                  },
                },
              },
            },

            response: {
              type: "object",
              properties: {
                headers: {
                  type: "string",
                },
                status: {
                  type: "string",
                },
                body: {
                  type: "string",
                },
                size: {
                  type: "number",
                },
                time: {
                  type: "number",
                },
              },
            },
            state: {
              type: "object",
              properties: {
                requestBodyLanguage: {
                  type: "string",
                },
                requestBodyNavigation: {
                  type: "string",
                },
                requestAuthNavigation: {
                  type: "string",
                },
                requestNavigation: {
                  type: "string",
                },
                responseNavigation: {
                  type: "string",
                },
                responseBodyLanguage: {
                  type: "string",
                },
                responseBodyFormatter: {
                  type: "string",
                },
                requestExtensionNavigation: {
                  type: "string",
                },
                requestLeftSplitterWidthPercentage: {
                  type: "number",
                },
                requestRightSplitterWidthPercentage: {
                  type: "number",
                },
                isExposeEditDescription: {
                  type: "boolean",
                },
                isSendRequestInProgress: {
                  type: "boolean",
                  default: false,
                },
                isSaveDescriptionInProgress: {
                  type: "boolean",
                  default: false,
                },
                isSaveRequestInProgress: {
                  type: "boolean",
                },
                isParameterBulkEditActive: {
                  type: "boolean",
                },
                isHeaderBulkEditActive: {
                  type: "boolean",
                },
                isChatbotActive: {
                  type: "boolean",
                },
                isChatbotSuggestionsActive: {
                  type: "boolean",
                },
                isChatbotGeneratingResponse: {
                  type: "boolean",
                },
                isDocAlreadyGenerated: {
                  type: "boolean",
                },
                isDocGenerating: {
                  type: "boolean",
                },
                selectedRequestAuthProfileId: {
                  type: "string",
                },
              },
            },
            auth: {
              type: "object",
              properties: {
                bearerToken: {
                  type: "string",
                },
                basicAuth: {
                  type: "object",
                  properties: {
                    username: {
                      type: "string",
                    },
                    password: {
                      type: "string",
                    },
                  },
                },
                apiKey: {
                  type: "object",
                  properties: {
                    authKey: {
                      type: "string",
                    },
                    authValue: {
                      type: "string",
                    },
                    addTo: {
                      type: "string",
                    },
                  },
                },
              },
            },
            ai: {
              type: "object",
              properties: {
                prompt: {
                  type: "string",
                },
                threadId: {
                  type: "string",
                },
                conversations: {
                  type: "array",
                  items: {
                    type: "object",
                    properties: {
                      messageId: {
                        type: "string",
                      },
                      message: {
                        type: "string",
                      },
                      type: {
                        type: "string",
                      },
                      isLiked: {
                        type: "boolean",
                      },
                      isDisliked: {
                        type: "boolean",
                      },
                      status: {
                        type: "boolean",
                      },
                    },
                  },
                },
              },
            },
            isGeneratedVariable: {
              type: "boolean",
            },
            isRequestTestsNoCodeDemoCompleted: {
              type: "boolean",
            },
            isRequestTestsScriptDemoCompleted: {
              type: "boolean",
            },
            isRequestAssertionsDemoCompleted: {
              type: "boolean",
            },
          },
        },
        savedRequest: {
          type: "object",
          properties: {
            method: {
              type: "string",
            },
            body: {
              type: "object",
              properties: {
                raw: {
                  type: "string",
                },
                urlencoded: {
                  type: "array",
                  items: {
                    type: "object",
                    properties: {
                      key: {
                        type: "string",
                      },
                      value: {
                        type: "string",
                      },
                      checked: {
                        type: "boolean",
                      },
                    },
                  },
                },
                formdata: {
                  type: "array",
                  items: {
                    type: "object",
                    properties: {
                      key: {
                        type: "string",
                      },
                      value: {
                        type: "string",
                      },
                      checked: {
                        type: "boolean",
                      },
                      base: {
                        type: "string",
                      },
                      type: {
                        type: "string",
                      },
                    },
                  },
                },
              },
            },
            responseBody: {
              type: "string",
            },
            url: {
              type: "string",
            },
            responseStatus: {
              type: "string",
            },
            responseDate: {
              type: "string",
            },
            headers: {
              type: "array",
              items: {
                type: "object",
                properties: {
                  key: {
                    type: "string",
                  },
                  value: {
                    type: "string",
                  },
                  checked: {
                    type: "boolean",
                  },
                },
              },
            },
            responseHeaders: {
              type: "array",
              items: {
                type: "object",
                properties: {
                  key: {
                    type: "string",
                  },
                  value: {
                    type: "string",
                  },
                  checked: {
                    type: "boolean",
                  },
                },
              },
            },
            queryParams: {
              type: "array",
              items: {
                type: "object",
                properties: {
                  key: {
                    type: "string",
                  },
                  value: {
                    type: "string",
                  },
                  checked: {
                    type: "boolean",
                  },
                },
              },
            },
            autoGeneratedHeaders: {
              type: "array",
              items: {
                type: "object",
                properties: {
                  key: {
                    type: "string",
                  },
                  value: {
                    type: "string",
                  },
                  checked: {
                    type: "boolean",
                  },
                },
              },
            },
            state: {
              type: "object",
              properties: {
                requestBodyLanguage: {
                  type: "string",
                },
                requestBodyNavigation: {
                  type: "string",
                },
                requestAuthNavigation: {
                  type: "string",
                },
                requestNavigation: {
                  type: "string",
                },
                responseNavigation: {
                  type: "string",
                },
                responseBodyLanguage: {
                  type: "string",
                },
                responseBodyFormatter: {
                  type: "string",
                },
                requestExtensionNavigation: {
                  type: "string",
                },
                requestLeftSplitterWidthPercentage: {
                  type: "number",
                },
                requestRightSplitterWidthPercentage: {
                  type: "number",
                },
                isExposeEditDescription: {
                  type: "boolean",
                },
                isSendRequestInProgress: {
                  type: "boolean",
                  default: false,
                },
                isSaveDescriptionInProgress: {
                  type: "boolean",
                  default: false,
                },
                isSaveRequestInProgress: {
                  type: "boolean",
                },
                isParameterBulkEditActive: {
                  type: "boolean",
                },
                isHeaderBulkEditActive: {
                  type: "boolean",
                },
              },
            },
            auth: {
              type: "object",
              properties: {
                bearerToken: {
                  type: "string",
                },
                basicAuth: {
                  type: "object",
                  properties: {
                    username: {
                      type: "string",
                    },
                    password: {
                      type: "string",
                    },
                  },
                },
                apiKey: {
                  type: "object",
                  properties: {
                    authKey: {
                      type: "string",
                    },
                    authValue: {
                      type: "string",
                    },
                    addTo: {
                      type: "string",
                    },
                  },
                },
              },
            },
            ai: {
              type: "object",
              properties: {
                prompt: {
                  type: "string",
                },
                threadId: {
                  type: "string",
                },
                conversations: {
                  type: "array",
                  items: {
                    type: "object",
                    properties: {
                      messageId: {
                        type: "string",
                      },
                      message: {
                        type: "string",
                      },
                      type: {
                        type: "string",
                      },
                      isLiked: {
                        type: "boolean",
                      },
                      isDisliked: {
                        type: "boolean",
                      },
                      status: {
                        type: "boolean",
                      },
                    },
                  },
                },
              },
            },
          },
        },
        folder: {
          type: "string",
        },
        collection: {
          type: "object",
          properties: {
            auth: {
              type: "object",
              properties: {
                bearerToken: {
                  type: "string",
                },
                basicAuth: {
                  type: "object",
                  properties: {
                    username: {
                      type: "string",
                    },
                    password: {
                      type: "string",
                    },
                  },
                },
                apiKey: {
                  type: "object",
                  properties: {
                    authKey: {
                      type: "string",
                    },
                    authValue: {
                      type: "string",
                    },
                    addTo: {
                      type: "string",
                    },
                  },
                },
              },
            },
            authProfiles,
            state: {
              type: "object",
              properties: {
                collectionAuthNavigation: {
                  type: "string",
                },
                collectionNavigation: {
                  type: "string",
                },
              },
            },
          },
        },
        workspace: {
          type: "string",
        },
        graphql: {
          type: "object",
          properties: {
            url: {
              type: "string",
            },
            query: {
              type: "string",
            },
            mutation: {
              type: "string",
            },
            schema: {
              type: "string",
            },
            headers: {
              type: "array",
              items: {
                type: "object",
                properties: {
                  key: {
                    type: "string",
                  },
                  value: {
                    type: "string",
                  },
                  checked: {
                    type: "boolean",
                  },
                },
              },
            },
            variables: {
              type: "string",
            },
            autoGeneratedHeaders: {
              type: "array",
              items: {
                type: "object",
                properties: {
                  key: {
                    type: "string",
                  },
                  value: {
                    type: "string",
                  },
                  checked: {
                    type: "boolean",
                  },
                },
              },
            },
            operationSearch: {
              type: "string",
            },
            state: {
              type: "object",
              properties: {
                requestNavigation: {
                  type: "string",
                },
                operationNavigation: {
                  type: "string",
                },
                requestAuthNavigation: {
                  type: "string",
                },
                requestLeftSplitterWidthPercentage: {
                  type: "number",
                },
                requestRightSplitterWidthPercentage: {
                  type: "number",
                },
                requestBuilderLeftSplitterWidthPercentage: {
                  type: "number",
                },
                requestBuilderRightSplitterWidthPercentage: {
                  type: "number",
                },
                isHeaderBulkEditActive: {
                  type: "boolean",
                },
                isRequestSchemaFetched: {
                  type: "boolean",
                },
              },
            },
            auth: {
              type: "object",
              properties: {
                bearerToken: {
                  type: "string",
                },
                basicAuth: {
                  type: "object",
                  properties: {
                    username: {
                      type: "string",
                    },
                    password: {
                      type: "string",
                    },
                  },
                },
                apiKey: {
                  type: "object",
                  properties: {
                    authKey: {
                      type: "string",
                    },
                    authValue: {
                      type: "string",
                    },
                  },
                },
              },
            },
          },
        },
        environment: {
          type: "object",
          properties: {
            variable: {
              type: "array",
              items: {
                type: "object",
                properties: {
                  key: {
                    type: "string",
                  },
                  value: {
                    type: "string",
                  },
                  checked: {
                    type: "boolean",
                  },
                },
                required: ["key", "value", "checked"],
              },
            },
            aIVariable: {
              type: "array",
              items: {
                type: "object",
                properties: {
                  key: {
                    type: "string",
                  },
                  value: {
                    type: "string",
                  },
                  checked: {
                    type: "boolean",
                  },
                },
                required: ["key", "value", "checked"],
              },
            },
            type: {
              type: "string",
            },
            state: {
              type: "object",
              properties: {
                isSaveInProgress: {
                  type: "boolean",
                },
              },
              required: ["isSaveInProgress"],
            },
          },
          required: ["variable", "aIVariable", "type", "state"],
        },
        websocket: {
          type: "object",
          properties: {
            url: {
              type: "string",
            },
            headers: {
              type: "array",
              items: {
                type: "object",
                properties: {
                  key: {
                    type: "string",
                  },
                  value: {
                    type: "string",
                  },
                  checked: {
                    type: "boolean",
                  },
                },
              },
            },
            queryParams: {
              type: "array",
              items: {
                type: "object",
                properties: {
                  key: {
                    type: "string",
                  },
                  value: {
                    type: "string",
                  },
                  checked: {
                    type: "boolean",
                  },
                },
              },
            },
            autoGeneratedHeaders: {
              type: "array",
              items: {
                type: "object",
                properties: {
                  key: {
                    type: "string",
                  },
                  value: {
                    type: "string",
                  },
                  checked: {
                    type: "boolean",
                  },
                },
              },
            },
            message: {
              type: "string",
            },
            state: {
              type: "object",
              properties: {
                socketNavigation: {
                  type: "string",
                },
                socketMessageLanguage: {
                  type: "string",
                },
                socketLeftSplitterWidthPercentage: {
                  type: "string",
                },
                socketRightSplitterWidthPercentage: {
                  type: "string",
                },
                isSaveSocketInProgress: {
                  type: "string",
                },
                isParameterBulkEditActive: {
                  type: "string",
                },
                isHeaderBulkEditActive: {
                  type: "string",
                },
              },
            },
          },
        },
        socketio: {
          type: "object",
          properties: {
            url: {
              type: "string",
            },
            headers: {
              type: "array",
              items: {
                type: "object",
                properties: {
                  key: {
                    type: "string",
                  },
                  value: {
                    type: "string",
                  },
                  checked: {
                    type: "boolean",
                  },
                },
              },
            },
            queryParams: {
              type: "array",
              items: {
                type: "object",
                properties: {
                  key: {
                    type: "string",
                  },
                  value: {
                    type: "string",
                  },
                  checked: {
                    type: "boolean",
                  },
                },
              },
            },
            autoGeneratedHeaders: {
              type: "array",
              items: {
                type: "object",
                properties: {
                  key: {
                    type: "string",
                  },
                  value: {
                    type: "string",
                  },
                  checked: {
                    type: "boolean",
                  },
                },
              },
            },
            message: {
              type: "string",
            },
            events: {
              type: "array",
              properties: {
                event: {
                  type: "string",
                },
                listen: {
                  type: "boolean",
                },
              },
            },
            eventName: {
              type: "string",
            },
            state: {
              type: "object",
              properties: {
                requestNavigation: {
                  type: "string",
                },
                messageLanguage: {
                  type: "string",
                },
                leftSplitterWidthPercentage: {
                  type: "string",
                },
                rightSplitterWidthPercentage: {
                  type: "string",
                },
                isSaveInProgress: {
                  type: "string",
                },
                isParameterBulkEditActive: {
                  type: "string",
                },
                isHeaderBulkEditActive: {
                  type: "string",
                },
              },
            },
          },
        },
        testflow: {
          type: "object",
          properties: {
            nodes: {
              type: "array",
              default: [],
              items: {
                type: "object",
                properties: {
                  id: {
                    type: "string",
                  },
                  type: {
                    type: "string",
                  },
                  data: {
                    type: "object",
                    properties: {
                      blockName: {
                        type: "string",
                      },
                      workspaceId: {
                        type: "string",
                      },
                      collectionId: {
                        type: "string",
                      },
                      folderId: {
                        type: "string",
                      },
                      requestId: {
                        type: "string",
                      },
                      requestData: {
                        type: "object",
                        properties: requestItems,
                      },
                      isDeleted: {
                        type: "boolean",
                      },
                    },
                  },
                  position: {
                    type: "object",
                    properties: {
                      x: {
                        type: "number",
                      },
                      y: {
                        type: "number",
                      },
                    },
                    required: ["x", "y"],
                  },
                },
                required: ["id", "type", "data", "position"],
              },
            },
            edges: {
              type: "array",
              default: [],
              items: {
                type: "object",
                properties: {
                  id: {
                    type: "string",
                  },
                  source: {
                    type: "string",
                  },
                  target: {
                    type: "string",
                  },
                },
                required: ["id", "source", "target"],
              },
            },
            state: {
              type: "object",
              properties: {
                testflowNavigator: {
                  type: "string",
                },
              },
            },
          },
        },
        aiRequest: {
          type: "object",
          properties: {
            aiModelProvider: {
              type: "string",
            },
            aiModelVariant: {
              type: "string",
            },
            systemPrompt: {
              type: "string",
            },
            configurations: {
              type: "object",
              properties: {
                openai: {
                  type: "object",
                  properties: {
                    streamResponse: {
                      type: "boolean",
                    },
                    jsonResponseFormat: {
                      type: "boolean",
                    },
                    temperature: {
                      type: "number",
                    },
                    presencePenalty: {
                      type: "number",
                    },
                    frequencyPenalty: {
                      type: "number",
                    },
                    maxTokens: {
                      type: "number",
                    },
                  },
                },
                deepseek: {
                  type: "object",
                  properties: {
                    streamResponse: {
                      type: "boolean",
                    },
                    jsonResponseFormat: {
                      type: "boolean",
                    },
                    temperature: {
                      type: "number",
                    },
                    presencePenalty: {
                      type: "number",
                    },
                    frequencyPenalty: {
                      type: "number",
                    },
                    maxTokens: {
                      type: "number",
                    },
                  },
                },
                anthropic: {
                  type: "object",
                  properties: {
                    streamResponse: {
                      type: "boolean",
                    },
                    maxTokens: {
                      type: "number",
                    },
                    temperature: {
                      type: "number",
                    },
                    top_p: {
                      type: "number",
                    },
                  },
                },
                google: {
                  type: "object",
                  properties: {
                    streamResponse: {
                      type: "boolean",
                    },
                    jsonResponseFormat: {
                      type: "boolean",
                    },
                    temperature: {
                      type: "number",
                    },
                    top_p: {
                      type: "number",
                    },
                    maxTokens: {
                      type: "number",
                    },
                  },
                },
              },
            },
            state: {
              type: "object",
              properties: {
                aiAuthNavigation: {
                  type: "string",
                },
                aiNavigation: {
                  type: "string",
                },
                aiLeftSplitterWidthPercentage: {
                  type: "number",
                },
                aiRightSplitterWidthPercentage: {
                  type: "number",
                },
                isAiSendRequestInProgress: {
                  type: "boolean",
                  default: false,
                },
                isSaveDescriptionInProgress: {
                  type: "boolean",
                  default: false,
                },
                isSaveRequestInProgress: {
                  type: "boolean",
                },
                isChatbotActive: {
                  type: "boolean",
                },
                isChatbotSuggestionsActive: {
                  type: "boolean",
                },
                isChatbotGeneratingResponse: {
                  type: "boolean",
                },
                isChatAutoClearActive: {
                  type: "boolean",
                },
                isChatbotConversationLoading: {
                  type: "boolean",
                },
                isConversationHistoryPanelOpen: {
                  type: "boolean",
                },
                isConversationHistoryLoading: {
                  type: "boolean",
                },
                isChatbotPromptBoxActive: {
                  type: "boolean",
                },
                selectedRequestAuthProfileId: {
                  type: "string",
                },
              },
            },
            auth: {
              type: "object",
              properties: {
                bearerToken: {
                  type: "string",
                },
                basicAuth: {
                  type: "object",
                  properties: {
                    username: {
                      type: "string",
                    },
                    password: {
                      type: "string",
                    },
                  },
                },
                apiKey: {
                  type: "object",
                  properties: {
                    authKey: {
                      type: "string",
                    },
                    authValue: {
                      type: "string",
                    },
                    addTo: {
                      type: "string",
                    },
                  },
                },
              },
            },
            ai: {
              type: "object",
              properties: {
                prompt: {
                  type: "string",
                },
                conversationId: {
                  type: "string",
                },
                conversationTitle: {
                  type: "string",
                },
                conversations: {
                  type: "array",
                  items: {
                    type: "object",
                    properties: {
                      messageId: {
                        type: "string",
                      },
                      message: {
                        type: "string",
                      },
                      type: {
                        type: "string",
                      },
                      isLiked: {
                        type: "boolean",
                      },
                      isDisliked: {
                        type: "boolean",
                      },
                      status: {
                        type: "boolean",
                      },
                    },
                  },
                },
              },
            },
          },
        },
        mockHistory: {
          type: "string",
        },
        hub: {
          type: "object",
          properties: {
            id: {
              type: "string",
              maxLength: 100,
            },
            name: {
              type: "string",
            },
            description: {
              type: "string",
            },
            hubUrl: {
              type: "string",
            },
            githubUrl: {
              type: "string",
            },
            xUrl: {
              type: "string",
            },
            linkedinUrl: {
              type: "string",
            },
            logo: {
              type: "object",
            },
            owner: {
              type: "string",
            },
            users: {
              type: "array",
              items: {
                type: "object",
                properties: {
                  id: {
                    type: "string",
                  },
                  email: {
                    type: "string",
                  },
                  name: {
                    type: "string",
                  },
                  role: {
                    type: "string",
                  },
                },
              },
            },
            createdAt: {
              type: "string",
            },
            createdBy: {
              type: "string",
            },
            updatedAt: {
              type: "string",
            },
            updatedBy: {
              type: "string",
            },
          },
        },
        testflowScheduleRunView: {
          type: "object",
          properties: {
            nodes: {
              type: "array",
              default: [],
              items: {
                type: "object",
                properties: {
                  id: { type: "string" },
                  type: { type: "string" },
                  data: {
                    type: "object",
                    properties: {
                      blockName: { type: "string" },
                      workspaceId: { type: "string" },
                      collectionId: { type: "string" },
                      folderId: { type: "string" },
                      requestId: { type: "string" },
                      requestData: {
                        type: "object",
                        properties: requestItems,
                      },
                      isDeleted: { type: "boolean" },
                    },
                  },
                  position: {
                    type: "object",
                    properties: {
                      x: { type: "number" },
                      y: { type: "number" },
                    },
                    required: ["x", "y"],
                  },
                },
                required: ["id", "type", "data", "position"],
              },
            },
            edges: {
              type: "array",
              default: [],
              items: {
                type: "object",
                properties: {
                  id: { type: "string" },
                  source: { type: "string" },
                  target: { type: "string" },
                },
                required: ["id", "source", "target"],
              },
            },
            results: {
              type: "array",
              default: [],
              items: {
                type: "object",
                properties: {
                  datasetItemIndex: { type: "number" },
                  failedRequests: { type: "number" },
                  successRequests: { type: "number" },
                  totalTime: { type: "string" },
                  status: { type: "string" },
                  createdAt: { type: "string" },
                  updatedAt: { type: "string" },
                  requests: {
                    type: "array",
                    items: {
                      type: "object",
                      properties: {
                        method: { type: "string" },
                        name: { type: "string" },
                        status: { type: "string" },
                        time: { type: "string" },
                        errorMessage: { type: "string" },
                        error: { type: "string" },
                      },
                    },
                  },
                  responses: {
                    type: "array",
                    items: {
                      type: "object",
                      properties: {
                        headers: {
                          type: "array",
                          items: {
                            type: "object",
                            properties: {
                              key: { type: "string" },
                              value: { type: "string" },
                            },
                            required: ["key", "value"],
                          },
                        },
                        status: { type: "string" },
                        body: { type: "string" },
                        time: { type: "number" },
                        size: { type: "number" },
                        responseContentType: {
                          type: "string",
                          enum: [
                            "JSON",
                            "XML",
                            "HTML",
                            "Text",
                            "JavaScript",
                            "Image",
                          ],
                        },
                      },
                    },
                  },
                },
                required: [
                  "datasetItemIndex",
                  "failedRequests",
                  "requests",
                  "responses",
                  "status",
                  "successRequests",
                  "totalTime",
                ],
              },
            },
            selectedDataset: {
              type: "object",
              properties: {
                id: { type: "string" },
                name: { type: "string" },
                formatType: { type: "string" },
                fileSize: { type: "string" },
              },
            },
            isScheduled: { type: "boolean" },
            scheduleName: { type: "string" },
            lastestExecuted: { type: "string" },
          },
          required: [
            "nodes",
            "edges",
            "results",
            "isScheduled",
            "scheduleName",
            "lastestExecuted",
          ],
        },
        testflowSchedule: {
          type: "object",
          properties: {
            notifications: {
              type: "object",
              properties: {
                receiveNotifications: { type: "string" },
                emails: {
                  type: "array",
                  items: {
                    type: "string",
                  },
                },
              },
            },
            runConfiguration: {
              type: "object",
              properties: {
                runCycle: { type: "string" },
                executeAt: { type: "string" },
                time: { type: "string" },
                intervalHours: { type: "number" },
                days: {
                  type: "array",
                  items: {
                    type: "number",
                  },
                },
              },
            },
            state: {
              type: "object",
              properties: {
                scheduleNavigator: { type: "string" },
              },
            },
            environmentId: { type: "string" },
            testflowDataSetId: { type: "string" },
          },
          required: [
            "state",
            "environmentId",
            "runConfiguration",
            "notifications",
            "testflowDataSetId",
          ],
        },
        testflowDataSet: {
          type: "object",
          properties: {
            name: { type: "string" },
            formatType: { type: "string" },
            fileSize: { type: "string" },
            fileUrl: { type: "string" },
            createdAt: { type: "string" },
            updatedAt: { type: "string" },
            createdBy: { type: "string" },
            updatedBy: { type: "string" },
            item: {
              type: "object",
              properties: {
                dataSet: {
                  type: "array",
                  items: {
                    type: "object",
                    additionalProperties: true,
                  },
                },
              },
              required: ["dataSet"],
            },
          },
          required: ["name", "formatType", "fileSize", "item"],
        },
      },
    },
    isActive: {
      type: "boolean",
    },
    isSaved: {
      type: "boolean",
    },
    path: {
      type: "object",
      properties: {
        workspaceId: {
          type: "string",
        },
        collectionId: {
          type: "string",
        },
        folderId: {
          type: "string",
        },
        testflowId: {
          type: "string",
        },
        testflowScheduleId: {
          type: "string",
        },
      },
    },
    timestamp: {
      type: "string",
      maxLength: 100,
    },
    index: {
      type: "number",
    },
  },
  required: ["id", "name", "property"],
  indexes: ["timestamp"],
} as const;

const schemaTyped = toTypedRxJsonSchema(tabSchemaLiteral);

export type TabDocType = ExtractDocumentTypeFromTypedRxJsonSchema<
  typeof schemaTyped
>;

export const tabSchema: RxJsonSchema<TabDocType> = tabSchemaLiteral;
